package com.easy.easylibdemo.ui.okgo;

import android.os.Bundle;
import android.widget.TextView;

import com.easy.easylibdemo.R;
import com.easy.easylibdemo.ui.okgo.model.RegisterUuid4AppBean;
import com.easy.easylibdemo.ui.okgo.model.RegisterUuid4AppImpl;
import com.easy.easylibdemo.ui.okgo.model.RegisterUuid4AppModel;
import com.easylib.base.BaseActivity;
import com.easylib.okhttp.IOnHttpListener;

import butterknife.Bind;
import okhttp3.Response;

/**
 * 作　　者: guyj
 * 修改日期: 2016/11/16
 * 描　　述: MVC框架下的OKGO应用
 * 备　　注:
 */
public class OkGoActivity extends BaseActivity implements IOnHttpListener {

    @Bind(R.id.tv_uuid)
    TextView tvUuid;
    private RegisterUuid4AppModel registerUuid4AppModel;
    private RegisterUuid4AppBean registerUuid4AppBean;

    @Override
    public int getContentViewId() {
        return R.layout.activity_ok_go;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        registerUuid4AppModel = new RegisterUuid4AppImpl();
    }

    @Override
    protected void initVariable() {

    }

    @Override
    protected void processLogic(Bundle savedInstanceState) {
        registerUuid4AppModel.getRegisterUuid4AppBean("123456", this);

    }

    private void showResult(Object o) {
        if (o instanceof RegisterUuid4AppBean){
            registerUuid4AppBean=(RegisterUuid4AppBean)o;
            tvUuid.setText(registerUuid4AppBean.getToken());
        }
    }

    @Override
    public void onSuccess(Object o) {
        showResult(o);
    }

    @Override
    public void onError(Response response, Exception e) {
        tvUuid.setText(e.getMessage());
    }

    @Override
    public void onCache(Object o) {
        showResult(o);
    }

    @Override
    public void onAfter() {

    }

}
